#pragma  once

#include "Containers/Containers.h"

#include "Misc/StdHead.h"

#include "Object/Object.h"
#include "Path/Path.h"

#include "Containers/ThreadSafePtr.h"
#include "Render/Material/RenderShader.h"
#include "ShaderStage.h"
#include "Shader.m.h"


RCLASS()
class WHENGINE_API RShader : public RObject
{
    ROBJECT
public:
    static TSharedObjectPtr<RShader> CreateShader(TVector<uint8_t> && SpvFileData, EShaderStage ShaderType);
    static TSharedObjectPtr<RShader> CreateShader(const TVector<uint8_t> & SpvFileData, EShaderStage ShaderType);
    static TSharedObjectPtr<RShader> CreateShader(const SPath & SpvFile, EShaderStage ShaderType);

    RShader();

    virtual ~RShader();

    uint8_t * GetData()
    {
        return Data.Data();
    }

    size_t GetDataSize()
    {
        return Data.Num();
    }

    void UpdateShaderData(TVector<uint8_t> && SpvFileData, EShaderStage ShaderType);

    std::shared_ptr<CRenderShader> GetRenderShader()
    {
        return RenderShader;
    }

    void PostLoadFromAsset() override;

    void SyncToRenderThread();
protected:
    std::shared_ptr<CRenderShader> RenderShader;

    RFIELD(SerializeAsBinary)
    TVector<uint8_t> Data;

    RFIELD()
    EShaderStage ShaderType;
};